from puremvc.interfaces import ICommand
from puremvc.patterns.command import SimpleCommand
import app_facade
import model
import view


class StartupCmd(SimpleCommand, ICommand):
    def execute(self, note):
        self.facade.register_proxy(model.MpProxy())


class HomeStartupCmd(SimpleCommand, ICommand):
    def execute(self, note):
        if self.facade.has_mediator(view.HomeMediator.NAME):
            self.facade.remove_mediator(view.HomeMediator.NAME)

        self.facade.register_mediator(view.HomeMediator(note.getBody()))


class NewMpStartupCmd(SimpleCommand, ICommand):
    def execute(self, note):
        if self.facade.has_mediator(view.NewMpMediator.NAME):
            self.facade.remove_mediator(view.NewMpMediator.NAME)

        self.facade.register_mediator(view.NewMpMediator(note.getBody()))


class MpsStartupCmd(SimpleCommand, ICommand):
    def execute(self, note):
        if self.facade.has_mediator(view.MpsMediator.NAME):
            self.facade.remove_mediator(view.MpsMediator.NAME)

        self.facade.register_mediator(view.MpsMediator(note.getBody()))


class GetHomeCmd(SimpleCommand, ICommand):
    def execute(self, note):
        mp_proxy = self.facade.retrieve_proxy(model.MpProxy.NAME)
        mp_proxy.retrieve_all_mps()
        self.sendNotification(app_facade.AppFacade.HOME_GOT)


class AddMpCmd(SimpleCommand, ICommand):
    def execute(self, note):
        fdict = note.getBody()
        MpProxy = self.facade.retrieve_proxy(model.MpProxy.NAME)
        if MpProxy.add_mp(fdict):
            self.sendNotification(app_facade.AppFacade.MP_ADDED)


class GetMpsCmd(SimpleCommand, ICommand):
    def execute(self, note):
        mp_proxy = self.facade.retrieve_proxy(model.MpProxy.NAME)
        mp_proxy.retrieve_all_mps()
        self.sendNotification(app_facade.AppFacade.MPS_GOT)
